/*
 * @Author       : NaN 353362604@qq.com
 * @Date         : 2023-03-15 10:40:11
 * @LastEditTime : 2023-06-26 16:29:40
 * @LastEditors  : NaN 353362604@qq.com
 * @FilePath     : \AdminStration\src\Common\Router\MenuNav\DiyList\BCCenterPush.jsx
 * @Description  :
 */
import './Scss/BCCenterPushBox.scss'
import { useBoolean, useRequest } from 'ahooks'
import { Button, Select, message } from 'antd'
import { Http } from '../../../Api'
import { useState, useEffect } from 'react'
import { BCCDrawerBox } from './BCCDrawerBox'

const ButtonArrList = [
    { uuid: '01', title: '上传摄像头表数据，及摄像头分组关系数据(VD_Camera)', url: 'posBCCenterPushPushCenterCamera' },
    { uuid: '02', title: '上传视频表数据(VD_Video)', url: 'posBCCenterPushPushCenterVideo' },
    {
        uuid: '03',
        title: '上传安全检查表数据，及附件数据，整改表，及整改表附件数据(SC_Security)',
        url: 'posBCCenterPushPushCenterSecurity',
    },
    { uuid: '04', title: '上传附件表数据(Sys_Attachment)', url: 'posBCCenterPushPushCenterAttachment' },
    { uuid: '05', title: '上传压力机抗折抗压一体机数据(LabStressMachine)', url: 'posBCCenterPushPushLabStressMachine' },
    { uuid: '06', title: '上传万能机数据(LabUniversalRebar)', url: 'posBCCenterPushPushLabUniversalRebars' },
    { uuid: '07', title: '上传标养室数据(LabHumiture)', url: 'posBCCenterPushPushLabHumiture' },
    { uuid: '08', title: '上传回弹仪数据(LabReboundHammer)', url: 'posBCCenterPushPushLabReboundHammer' },
    { uuid: '09', title: '上传钢筋保护层数据(LabCoverProtector)', url: 'posBCCenterPushPushLabCoverProtector' },
    { uuid: '10', title: '上传马歇尔数据(LabMarshallStability)', url: 'posBCCenterPushPushLabMarshallStability' },
    { uuid: '11', title: '上传延度仪数据(LabDuctility)', url: 'posBCCenterPushPushLabDuctility' },
    { uuid: '12', title: '上传软化点数据(LabSofteningPoint)', url: 'posBCCenterPushPushLabSofteningPoint' },
    { uuid: '13', title: '上传针入度数据(Lab_LabPenetration)', url: 'posBCCenterPushPushLabPenetration' },
    { uuid: '14', title: '上传CBR数据(LabPmsTesterCbr)', url: 'posBCCenterPushPushLabPmsTesterCbr' },
    { uuid: '15', title: '上传文件柜数据(Info_InfoManage)', url: 'posBCCenterPushPushInfoManage' },
]

export const BCCenterPush = () => {
    const [GetSelects, setGetSelects] = useState([])
    const [UpdateSelect, setUpdateSelect] = useState('')
    const { runAsync: getDataSynchronizationGetSelects } = useRequest(Http, {
        manual: true,
        onSuccess: res => {
            const [{ uuid }] = res
            setUpdateSelect(uuid)
            setGetSelects(res)
        },
    })

    const { runAsync: BCCenterPush } = useRequest(Http, {
        manual: true,
        onSuccess: res => {
            message.success(res)
            setFalse()
        },
    })
    const [DrawerUrl, setDrawerUrl] = useState()
    const [DrawerStatus, { setTrue, setFalse }] = useBoolean(false)
    const AllUpdate = url => BCCenterPush({ url, path: [UpdateSelect, '', 0] })
    useEffect(() => {
        getDataSynchronizationGetSelects({ url: 'getDataSynchronizationGetSelects' })
    }, [getDataSynchronizationGetSelects])

    return (
        <div className="BCCenterPushBox">
            <div className="DiyBoxTitle">
                <div className="left">
                    <div>系统配置</div>
                    <div>同步上传</div>
                </div>
            </div>
            <div className="BtnList">
                {/* uuids  string */}
                {/* pushtype   select  1手动  0自动 */}

                <div>
                    <div className="label">上传位置 : </div>
                    <Select
                        fieldNames={{ label: 'centName', value: 'uuid' }}
                        options={GetSelects}
                        value={UpdateSelect}
                        onChange={e => setUpdateSelect(e)}
                    />
                </div>
                {ButtonArrList.map(({ uuid, title, url }) => (
                    <div key={uuid}>
                        <div className="label">{title} : </div>
                        <Button
                            style={{ marginRight: 16 }}
                            type="primary"
                            onClick={() => {
                                setDrawerUrl(url)
                                setTrue()
                            }}
                        >
                            手动同步数据
                        </Button>
                        <Button type="primary" onClick={() => AllUpdate(url)}>
                            自动同步数据
                        </Button>
                    </div>
                ))}
            </div>
            {DrawerStatus && DrawerUrl && (
                <BCCDrawerBox url={DrawerUrl} Off={setFalse} BCCenterPush={BCCenterPush} UpdateSelect={UpdateSelect} />
            )}
        </div>
    )
}
